package com.haojii.notifier.easytv;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class EasytvItem {

	public EasytvItem(String itemTitle, String itemLink) {
		super();
		this.key = KeyFactory.createKey(EasytvItem.class.getSimpleName(), itemTitle+","+itemLink);
		this.itemTitle = itemTitle;
		this.itemLink = itemLink;
		this.updatedTime = new Date();
	}
	@Override
	public String toString() {
		return "EasytvItem [itemLink=" + itemLink + ", itemTitle=" + itemTitle
				+ ", updatedTime=" + new SimpleDateFormat("YYYY-MM-DD HH:mm:SS").format(updatedTime)
				+ "]";
	}
	
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

	@Persistent
	String itemTitle;
	
	@Persistent
	String itemLink;
	
	@Persistent
	Date updatedTime;
	
/*	@Persistent
	EasytvEntity easytvEntity;*/
	
	public String getItemTitle() {
		return itemTitle;
	}
	public void setItemTitle(String itemTitle) {
		this.itemTitle = itemTitle;
	}
	public String getItemLink() {
		return itemLink;
	}
	public void setItemLink(String itemLink) {
		this.itemLink = itemLink;
	}
/*	public EasytvEntity getEasytvEntity() {
		return easytvEntity;
	}
	public void setEasytvEntity(EasytvEntity easytvEntity) {
		this.easytvEntity = easytvEntity;
	}*/
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((itemLink == null) ? 0 : itemLink.hashCode());
		result = prime * result
				+ ((itemTitle == null) ? 0 : itemTitle.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		EasytvItem other = (EasytvItem) obj;
		if (itemLink == null) {
			if (other.itemLink != null)
				return false;
		} else if (!itemLink.equals(other.itemLink))
			return false;
		if (itemTitle == null) {
			if (other.itemTitle != null)
				return false;
		} else if (!itemTitle.equals(other.itemTitle))
			return false;
		return true;
	}
	public Date getUpdatedTime() {
		return updatedTime;
	}
	public void setUpdatedTime(Date updatedTime) {
		this.updatedTime = updatedTime;
	}

}
